/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.blitzcoder.collide.config.textarea;

import de.blitzcoder.collide.gui.textarea.CollIDETextArea;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.gjt.sp.jedit.syntax.SyntaxStyle;
import org.gjt.sp.util.SyntaxUtilities;

/**
 *
 * @author blitzcoder
 */
class PreviewPanel extends JPanel {
        
        private JLabel label;
        private SyntaxStyle style;
        
        protected PreviewPanel(String propName) {
            
            super();
            
            label = new JLabel("Sample Text");
            
            setLayout(new GridLayout());
            add(label);
            
            setOpaque(true);
            
            setProperty(propName);
        }
        
        protected PreviewPanel(SyntaxStyle style) {
            
            super();
            
            label = new JLabel("Sample Text");
            
            setLayout(new GridLayout());
            add(label);
            
            setOpaque(true);
            
            setStyle(style);
        }
        
        public void setProperty(String name) {
            style = CollIDETextArea.getPropertyManager().getSyntaxStyleProperty(name);
            
            setBackground(style.getBackgroundColor());
            label.setForeground(style.getForegroundColor());
            label.setFont(style.getFont());
            
            repaint();
        }
        
        public void setStyle(String styletxt) {
            style = SyntaxUtilities.parseStyle(styletxt,CollIDETextArea.getPropertyManager().getProperty("view.font"),CollIDETextArea.getPropertyManager().getIntProperty("view.fontsize"),true);
            
            setBackground(style.getBackgroundColor());
            label.setForeground(style.getForegroundColor());
            label.setFont(style.getFont());
            
            repaint();
        }
        
        public void setStyle(SyntaxStyle style) {



            this.style = style;
            
            setBackground(style.getBackgroundColor());
            label.setForeground(style.getForegroundColor());
            label.setFont(style.getFont());
            
            repaint();
        }
        
        public SyntaxStyle getStyle() {
            return style;
        }
        
    }
